#include <QCoreApplication>  // 必须包含 QCoreApplication
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDebug>

int main(int argc, char *argv[]) {
    QCoreApplication app(argc, argv);  // 创建 QCoreApplication 实例

    QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("test.db");
    if (!db.open()) {
        qDebug() << "Database open failed!";
        return 1;
    }

    QSqlQuery query;
    query.exec("CREATE TABLE person (id INT PRIMARY KEY, name TEXT)");
    query.exec("INSERT INTO person VALUES (1, 'Alice')");
    query.exec("INSERT INTO person VALUES (2, 'Bob')");
    qDebug() << "Table created and data inserted.";

    return app.exec();  // 启动事件循环，避免程序立即退出
}
